package android.storefront.bussiness;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.storefront.activity.R;
import android.storefront.common.utils.sound.SoundPoolUtils;
import android.storefront.valueobject.GridViewVO;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;

public class MainActivityDataHandler {

	private static MainActivityDataHandler mainActivityDataHandler = new MainActivityDataHandler();

	public static MainActivityDataHandler getInstance() {
		return mainActivityDataHandler;
	}
	
	

	public class GridViewAdapter extends BaseAdapter {

		private Context context;
		private Activity activity;
		private List<GridViewVO> list = null;

		public GridViewAdapter(Context context, Activity activity,
				List<GridViewVO> list) {
			this.context = context;
			this.list = list;
			this.activity = activity;
		}

		@Override
		public int getCount() {
			return list.size();
		}

		@Override
		public Object getItem(int arg0) {
			return list.get(arg0);
		}

		@Override
		public long getItemId(int arg0) {
			return arg0;
		}

		@Override
		public View getView(int index, View view, ViewGroup viewGroup) {
			LinearLayout linearLayout = new LinearLayout(context);
			linearLayout.setBackgroundResource(R.drawable.click_drawable);
			linearLayout.setOrientation(LinearLayout.VERTICAL);

			ImageView iv = new ImageView(context);
			iv.setImageBitmap(((BitmapDrawable) context.getResources().getDrawable(list.get(index).getImageId())).getBitmap());
			LinearLayout.LayoutParams params2 = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
			params2.gravity = Gravity.CENTER;
			linearLayout.addView(iv, params2);

			TextView tv = new TextView(context);
			tv.setTextSize(14);
			tv.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
			tv.setText(context.getResources().getText(list.get(index).getName()));
			LinearLayout.LayoutParams params3 = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
			params3.gravity = Gravity.CENTER;

			linearLayout.addView(tv, params3);

			linearLayout.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					SoundPoolUtils.getInstance(context).playSound(SoundPoolUtils.SOUND_BUTTON_CLICK);
				}
			});

			return linearLayout;
		}
	}

}
